import Vue from 'vue'
import Vuex from 'vuex'

const state = {
  xzNumber: 0
}
const mutations = {
  INCREMENT(state) {
    state.xzNumber++
  },
  DECREMENT(state) {
    state.xzNumber--
  }
}
const actions = {
  increment({commit}) {
    commit('INCREMENT')
  },
  decrement({commit}) {
    commit('DECREMENT')
  },
  incrementOdd({commit, state}) {
    if (state.xzNumber % 2 === 1) {
      commit('INCREMENT')
    }
  },
  incrementAsnyc({commit}) {
    setTimeout(() => {
      commit('INCREMENT')
    }, 1000)
  }
}
const getters = {
  oddOreven(state){
    return state.xzNumber % 2 === 0 ? '偶数' : '奇数'
  },
  count(state){
    return state.xzNumber
  }

}


Vue.use(Vuex)
export default new Vuex.Store({
  state,
  actions,
  mutations,
  getters,

})
